package com.eastfair.certificate.enumeration;

import com.eastfair.annotation.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

/**
 * <p>
 * 实体注释中生成的类型枚举
 * 动态表单
 * </p>
 *
 * @author ligang
 * @date 2022-07-14
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "FormFieldFieldGroupEnum", description = "表单分组类型 #{PERSONAL:个人;COMPANY:公司;CERTIFICATE:制证;-枚举")
public enum FormFieldFieldGroupEnum implements BaseEnum {

    /**
     * PERSONAL="个人"
     */
    PERSONAL("个人"),
    /**
     * COMPANY="公司"
     */
    COMPANY("公司"),
    /**
     * CERTIFICATE="制证"
     */
    CERTIFICATE("制证"),
    ;

    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static FormFieldFieldGroupEnum match(String val, FormFieldFieldGroupEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static FormFieldFieldGroupEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(FormFieldFieldGroupEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "PERSONAL,COMPANY,CERTIFICATE", example = "PERSONAL")
    public String getCode() {
        return this.name();
    }

}
